PrepDiets: PropTypes.array.isRequired,
PrepDietsSub: PropTypes.array.isRequired,
};
static defaultProps = {
token: '',
}
static async getInitialProps({ query, authToken }) {
const serverFoodPrepTablesAPI = new FoodPrepTables(authToken);
const serverDietsAPI = new Diets(authToken);
try {
const [
AllFoodPrepTables,
AllFoodPrep,
] = await Promise.all([
serverFoodPrepTablesAPI.getFoodPrepTables(),
serverDietsAPI.getAnimalPrep(query.date),
]);
return {
...query,
FoodPrepTables: AllFoodPrepTables.data,
PrepDiets: AllFoodPrep.data.diets,
PrepDietsSub: AllFoodPrep.data.dietsSub,
};
} catch (err) {
console.error(err);
return {
error: true,
FoodPrepTables: [],
PrepDiets: [],
PrepDietsSub: [],
};
}
}
constructor(props) {
super(props);
this.state = {
table: 0,
diets: [],
currentIndex: 0,
species: '',
prepNotes: ['none', 'newline?'],
dc: '',
dietChanges: ['none'],
foodPrep: [],
};
this.serverDietsAPI = new Diets(this.props.token);
this.serverSpeciesAPI = new Species(this.props.token);
this.serverPrepNotesAPI = new PrepNotes(this.props.token);
this.serverDeliverContainersAPI = new DeliveryContainers(this.props.token);
this.serverDietChangesAPI = new DietChanges(this.props.token);
}
async getDietsData(tableID) {
const [
diets,
] = await Promise.all([
this.serverDietsAPI.getDiets({
where: {
tableId: tableID,
},
}),
]);
this.setState({
diets: diets.data,
});
}
async getKitchenData(speciesID, dietID, dcID) {
const [
species,
prepNotes,
dc,
dietChanges,
] = await Promise.all([
this.serverSpeciesAPI.getSpecies({
where: {
speciesId: speciesID,
},
}),
this.serverPrepNotesAPI.getPrepNotes({
where: {
dietId: dietID,
},
}),
this.serverDeliverContainersAPI.getDeliveryContainers({
where: {
dcId: dcID,
},
}),
this.serverDietChangesAPI.getDietChanges({
where: {
dietId: dietID,
},
}),
]);
this.setState({
species: species.data[0].species,
prepNotes: prepNotes.data,
dc: dc.data[0].dc,
dietChanges: dietChanges.data.slice(0, 3),
foodPrep: this.getPrepFood(dietID),
});
}